# $NetBSD: Makefile,v 1.1 2015/07/14 11:10:49 ahp-nils Exp $

DISTNAME=	php-malware-finder-0.3.4
CATEGORIES=	security
MASTER_SITES=	${MASTER_SITE_GITHUB:=nbs-system/}

MAINTAINER=	nils@NetBSD.org
HOMEPAGE=	https://github.com/nbs-system/php-malware-finder/
COMMENT=	Detect potentially malicious PHP files
LICENSE=	gnu-lgpl-v3

DEPENDS+=	yara>=3.4.0:../../security/yara
NO_BUILD=	yes
USE_LANGUAGES=	# none
USE_TOOLS+=	bash:run pax
EGDIR=		${PREFIX}/share/examples/php-malware-finder

PKG_SYSCONFSUBDIR=	phpmalwarefinder

.for config in asp.yar common.yar php.yar whitelist.yar
CONF_FILES+=	${EGDIR}/${config} ${PKG_SYSCONFDIR}/${config}
.endfor

.for whitelist in custom.yar drupal.yar magento2.yar phpmyadmin.yar prestashop.yar symfony.yar wordpress.yar
CONF_FILES+=	${EGDIR}/whitelists/${whitelist} ${PKG_SYSCONFDIR}/whitelists/${whitelist}
.endfor

INSTALLATION_DIRS+=	bin ${DOCDIR} share/php-malware-finder \
			share/php-malware-finder/samples share/php-malware-finder/utils \
			${EGDIR} ${EGDIR}/whitelists/ \
			${PKG_SYSCONFDIR} ${PKG_SYSCONFDIR}/whitelists/

AUTO_MKDIRS=	yes
DOCDIR=		share/doc/php-malware-finder

REPLACE_INTERPRETER+=	bash
REPLACE.bash.old=	.*sh[^ ]*
REPLACE.bash.new=	${TOOLS_PATH.bash}
REPLACE_FILES.bash=	${WRKSRC}/php-malware-finder/phpmalwarefinder
REPLACE_FILES.bash+=	${WRKSRC}/php-malware-finder/docroot-check.sh
REPLACE_FILES.bash+=	${WRKSRC}/php-malware-finder/tests.sh

SUBST_CLASSES+=		install
SUBST_STAGE.install=	pre-install
SUBST_MESSAGE.install=	correcting installation path
SUBST_FILES.install=	${WRKSRC}/php-malware-finder/phpmalwarefinder
SUBST_FILES.install+=	${WRKSRC}/php-malware-finder/docroot-check.sh
SUBST_SED.install=	-e 's,/etc/phpmalwarefinder,${PREFIX}/etc/phpmalwarefinder,g'

do-install:
.for conffile in asp.yar common.yar php.yar whitelist.yar
	${INSTALL_DATA} ${WRKSRC}/php-malware-finder/${conffile} ${DESTDIR}${EGDIR}
.endfor
.for whitelistfile in custom.yar drupal.yar magento2.yar phpmyadmin.yar prestashop.yar symfony.yar wordpress.yar
	${INSTALL_DATA} ${WRKSRC}/php-malware-finder/whitelists/${whitelistfile} ${DESTDIR}${EGDIR}/whitelists/
.endfor
	${INSTALL_SCRIPT} ${WRKSRC}/php-malware-finder/phpmalwarefinder ${DESTDIR}${PREFIX}/bin
	${INSTALL_SCRIPT} ${WRKSRC}/php-malware-finder/docroot-check.sh ${DESTDIR}${PREFIX}/bin
	${INSTALL_DATA} ${WRKSRC}/php-malware-finder/utils/generate_whitelist.py ${DESTDIR}${PREFIX}/share/php-malware-finder/utils/
	${INSTALL_DATA} ${WRKSRC}/php-malware-finder/utils/mass_whitelist.py ${DESTDIR}${PREFIX}/share/php-malware-finder/utils/
	${INSTALL_DATA} ${WRKSRC}/php-malware-finder/tests.sh ${DESTDIR}${PREFIX}/share/php-malware-finder/
	${INSTALL_DATA} ${WRKSRC}/LICENSE ${DESTDIR}${PREFIX}/${DOCDIR}
	${INSTALL_DATA} ${WRKSRC}/README.md ${DESTDIR}${PREFIX}/${DOCDIR}
	${INSTALL_DATA} ${WRKSRC}/RELEASE.md ${DESTDIR}${PREFIX}/${DOCDIR}
	cd ${WRKSRC}/php-malware-finder/samples && pax -rw -pm . ${DESTDIR}${PREFIX}/share/php-malware-finder/samples

.include "../../mk/bsd.pkg.mk"
